package com.liyongjian.page.job;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.liyongjian.page.dal.VisitRepository;
import com.liyongjian.page.domain.Visit;
import com.liyongjian.page.domain.enumm.RepState;
import com.liyongjian.page.service.VisitService;

@Component
public class ReportTask {

    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private VisitService visitService;
    @Autowired
    private VisitRepository visitRepository;

    @Scheduled(cron = "0 */2 * * * ?")
    public void report() {
        List<Visit> visits = visitRepository.findByRepStateAndCreatedAt(RepState.WCL, new Date());
        for (Visit visit : visits) {
            visitService.reportPage(visit);
        }
    }

}
